 package com.manager.car.action;



import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.google.gson.Gson;
import com.manager.car.po.CarRoom;
import com.manager.car.service.ICarRoomService;
import com.manager.car.util.PageModel;
import com.opensymphony.xwork2.ActionSupport;


/**
 * @param 登录模板Action类
 * @author xiaoge
 * @Date 2018年11月22日10:54:34
 */

public class CarRoomAction extends ActionSupport {
	private static final long serialVersionUID = 1L;
	private ICarRoomService service;//ImanagerInfoService服务
	private PageModel<CarRoom> pageModel;
	private CarRoom carRoom;
	private Integer id;
	private Integer limit;
	private Integer page;
	
	//添加
	public void addCarRoom() throws IOException{
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setContentType("application/json");
		response.setCharacterEncoding("utf-8");
		PrintWriter out = response.getWriter();
		boolean bool = service.addCarRoom(carRoom);
		out.print(bool);
		out.flush();
		out.close();
	}
	
	//删除carroom
	public void deleteCarRoomById() throws IOException {
		
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setContentType("application/json");
		response.setCharacterEncoding("utf-8");
		PrintWriter out = response.getWriter();
		
		boolean bool = service.deleteCarRoomById(id);
		
		out.print(bool);
		out.flush();
		out.close();
	}
	//客户提车
	public void updateCarRoomEndTimeById() throws IOException {
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setContentType("application/json");
		response.setCharacterEncoding("utf-8");
		PrintWriter out = response.getWriter();
		boolean bool = service.updateCarRoomEndTimeById(id);
		
		out.print(bool);
		out.flush();
		out.close();
	}
	
	//查询所有的管理员信息
	public void queryPageModelFromCarRoom() throws IOException {
		
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setContentType("application/json");
		response.setCharacterEncoding("utf-8");
		PrintWriter out = response.getWriter();
		if(page==null) {
			page = 1;
		}
		if(limit==null) {
			limit=15;
		}
		PageModel<CarRoom> data = service.queryPageModelByHql(page,limit);
		
		Gson gson = new Gson();
		String json = gson.toJson(data);
		
		out.print(json);
		out.flush();
		out.close();
	}

	public ICarRoomService getService() {
		return service;
	}

	public void setService(ICarRoomService service) {
		this.service = service;
	}

	public PageModel<CarRoom> getPageModel() {
		return pageModel;
	}

	public void setPageModel(PageModel<CarRoom> pageModel) {
		this.pageModel = pageModel;
	}

	public CarRoom getCarRoom() {
		return carRoom;
	}

	public void setCarRoom(CarRoom carRoom) {
		this.carRoom = carRoom;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Integer getLimit() {
		return limit;
	}

	public void setLimit(Integer limit) {
		this.limit = limit;
	}

	public Integer getPage() {
		return page;
	}

	public void setPage(Integer page) {
		this.page = page;
	}
	
	
	
}
